package com.ztf0337.mycurriculumdesign.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.ztf0337.mycurriculumdesign.entity.Order;
import com.ztf0337.mycurriculumdesign.entity.ParkingSpace;
import com.ztf0337.mycurriculumdesign.entity.RentedParkingSpace;

import java.util.List;

@Dao
public interface OrderDao {

    @Insert
    long insert(Order order);
    @Delete
    void delete(Order order);
    @Update
    void update(Order order);
    @Query("SELECT * FROM order_table WHERE id = :id")
    Order getOrderById(Long id);
    @Query("SELECT * FROM order_table WHERE user_id = :id")
    List<Order> getOrdersByUserId(Long id);

    @Query("SELECT * FROM order_table WHERE order_number =:content " +
            "AND user_id = :user_id")
    List<Order> searchOrderByOrderNumber(String content, Long user_id);

    @Query("SELECT * FROM order_table WHERE parking_space_number LIKE '%' || :content || '%' " +
            "AND user_id = :user_id")
    List<Order> searchOrderBySpaceNumber(String content, Long user_id);

    @Query("SELECT * FROM order_table WHERE order_number =:content ")
    List<Order> searchAllOrderByOrderNumber(String content);

    @Query("SELECT * FROM order_table WHERE parking_space_number LIKE '%' || :content || '%' ")
    List<Order> searchAllOrderBySpaceNumber(String content);
    @Query("SELECT * FROM order_table")
    List<Order> getAll();


    @Query("DELETE FROM order_table WHERE user_id = :id")
    void deleteOrdersByUserId(Long id);
}
